The HTML <video> element allows embedding video content into a webpage. It provides built-in controls, supports multiple formats, and allows features like autoplay, looping, and subtitles.
✔️ No need for external plugins (e.g., Flash)
✔️ Supports multiple video formats
✔️ Customizable with JavaScript & CSS
Explanation
✔️ <video> creates the video player.
✔️ <source> provides multiple formats for browser compatibility.
✔️ <controls> adds play, pause, volume, and fullscreen options.
✔️ Fallback text appears if the browser doesn't support <video>.
Attributes of the <video> Element
Attribute
Description
`controls`
Displays play, pause, and volume controls.
`autoplay`
Starts playing the video automatically.
`loop`
Repeats the video when it ends.
`muted`
Starts the video muted.
`poster`
Displays an image before the video plays.
`preload`
Defines how the browser loads the video (`auto`, `metadata`, `none`).
`width` & `height`
Specifies the size of the video player.
Example using autoplay, loop, and poster
✔️ This automatically plays the video, loops it, and starts muted.
✔️ The `poster` attribute shows a thumbnail before playing.
Supported Video Formats and Browser Compatibility
format
File Extension
Supported Browsers
MP4
`.mp4`
Chrome, Firefox, Safari, Edge, Opera
WebM
`.webm`
Chrome, Firefox, Edge, Opera
Ogg
`.ogg`
Chrome, Firefox, Edge, Opera
Best Practice: Provide multiple formats (`MP4`, `WebM`, `Ogg`) for better browser support.
Adding Captions & Subtitles
Captions improve accessibility and SEO. Use the <track> element for subtitles.
✔️ <track> loads subtitles from a `.vtt` file.
✔️ `kind="subtitles"` specifies subtitle text.
Example `.vtt` file (e.g, subtitles.vtt)
WEBVTT
00:00:00.000 --> 00:00:05.000
Welcome to the HTML video tutorial.
00:00:05.000 --> 00:00:10.000
Here, you will learn how to use the video element.
Remember: My Video already has it's subtitle
Using JavaScript with <video>
JavaScript provides custom controls for videos.
Example: Custom Play/Pause Button
Applications of the <video> Element
✔️ Online Streaming – Used for video platforms like YouTube.
✔️ Use the <source> tag for multiple video formats.
✔️ Optimize file size using compression tools like HandBrake.
✔️ Always provide a <pastor> image for better user experience.
✔️ Use captions (<track>) to improve accessibility.
✔️ Use JavaScript for enhanced playback control.
The HTML <video> element is a powerful and efficient way to add videos to websites. It provides native playback controls, supports multiple formats, and integrates well with JavaScript & CSS. However, to ensure smooth performance, it is essential to optimize file sizes, provide multiple formats, and implement best practices.